package mastermind.gui;

import java.awt.Dimension;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.Action;

import mastermind.gui.actions.SaveSettingsAction;

public class SettingsFrame extends JFrame{
	
	private JPanel topPanel;
	private JLabel lblAddress;
	private JLabel lblPort;
	
	private JTextField txtAddress;
	private JTextField txtPort;
	
	private Action saveAction;
	
	private JButton btnSave;
	
	/**
	 * get IP address
	 */
	public String getIPAddress()
	{
		return txtAddress.getText();
	}
	
	/**
	 * get port number
	 */
	public String getPort()
	{
		return txtPort.getText();
	}
	
	public SettingsFrame(Frame mainFrame)
	{
		saveAction = new SaveSettingsAction(mainFrame, this);
		topPanel = new JPanel();
    	topPanel.setPreferredSize(new Dimension(230,125));
    	topPanel.setLayout(new GridLayout(3,2));
    	this.getContentPane().add(topPanel);
    	
    	lblAddress = new JLabel("IP Address:");
    	lblPort = new JLabel("Port:");
    	txtAddress = new JTextField();
    	txtAddress.setText(mainFrame.getServerAddress());
    	txtPort = new JTextField();
    	txtPort.setText(mainFrame.getServerPort());
    	btnSave = new JButton(saveAction);
    	btnSave.setText("Save"); //create components and add them to panel
    	
    	topPanel.add(lblAddress);
    	topPanel.add(txtAddress);
    	topPanel.add(lblPort);
    	topPanel.add(txtPort);
    	topPanel.add(btnSave);
    	
    	this.setTitle("Server Settings");
    	this.setSize(new Dimension(230,125));
    	this.setLocationRelativeTo(null);
    	this.setResizable(false);
	}

}
